import request from "./request.js";
// 註冊
export function register(params) {
	return request("/api/user/register", "POST", params)
}
// 登錄
export function login(params) {
	return request("/api/user/login", "POST", params)
}
// 计算价格
export function imputedPrice(params) {
	return request("/api/order/predict_order", "POST", params)
}
// 驗證碼登錄
export function codeLogin(params) {
	return request("/api/user/mobilelogin", "POST", params)
}
// 重置密碼
export function changePassword(params) {
	return request("/api/user/resetpwd", "POST", params)
}
// 退出登錄
export function myLoginOut(params) {
	return request("/api/user/logout", "POST", params)
}
// 提交投诉建议
export function toFeedback(params) {
	return request("/api/user/feedback", "POST", params)
}
// 获取协议
export function getArticle(params) {
	return request("/api/index/article", "POST", params)
}
// 客服信息
export function getServiceInfor(params) {
	return request("/api/index/service", "POST", params)
}
// 邀請二維碼
export function inviteCode(params) {
	return request("/api/user/invite_qrcode", "POST", params)
}
// 獲取個人信息
export function mineInfor(params) {
	return request("/api/user/index", "POST", params)
}
// 修改個人信息
export function changeMineInfor(params) {
	return request("/api/user/profile", "POST", params)
}
// 確認下單
export function createOrder(params) {
	return request("/api/order/create_order", "POST", params)
}
// 確認取消訂單
export function cancelOrder(params) {
	return request("/api/order/order_cancel", "POST", params)
}
// 订单详情
export function orderDetails(params) {
	return request("/api/order/order_detail", "POST", params)
}
// 獲取訂單狀態
export function getCarStatus(params) {
	return request("/api/order/get_driver_car_detail", "POST", params)
}
// 计价规则
export function getPriceRuler(params) {
	return request("/api/index/city_set", "POST", params)
}
// 訂單列表
export function orderList(params) {
	return request("/api/order/order_list", "POST", params)
}
// 地理位置反向编码
export function getNowAddress(latlng,language) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://maps.googleapis.com/maps/api/geocode/json',
			method: 'GET',
			data: {
				key:'AIzaSyBp7LF3tHEomcoYojzqArmIKYNuY1VL5CE',
				latlng:latlng,
				language:language=='0'?'zh-hk':'en-us'
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete() {

			}
		});
	});
}
// 获取路径规划
export function getDirections(params,language) {
	return new Promise((resolve, reject) => {
		console.log(params);
		uni.request({
			url: 'https://maps.googleapis.com/maps/api/directions/json',
			method: 'GET',
			data: {
				key:'AIzaSyBp7LF3tHEomcoYojzqArmIKYNuY1VL5CE',
				mode:'driving',
				language:language=='0'?'zh-hk':'en-us',
				...params
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete() {

			}
		});
	});
}
// 搜索地址
export function selectAddress(params,language) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://maps.googleapis.com/maps/api/place/textsearch/json',
			method: 'GET',
			data: {
				key:'AIzaSyBp7LF3tHEomcoYojzqArmIKYNuY1VL5CE',
				language:language=='0'?'zh-hk':'en-us',
				sensor:true,
				...params
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete() {

			}
		});
	});
}
export function getDistances(lat1, lng1, lat2, lng2) {
	var radLat1 = rad(lat1);
	var radLat2 = rad(lat2);
	var a = radLat1 - radLat2;
	var b = rad(lng1) - rad(lng2);
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
		Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * 6378.137; // EARTH_RADIUS;
	// 输出为公里
	s = Math.round(s * 10000) / 10000;

	var distance = s;
	var distance_str = "";

	if (parseInt(distance) >= 1) {
		;
		distance_str = distance.toFixed(2) + "km";
	} else {
		distance_str = (distance * 1000).toFixed(2) + "m";
	}
	return distance_str
}
//	角度转换成弧度
const rad = (d) => {
	return d * Math.PI / 180.00;
};